/**
 * 
 */
package com.pengtu.entity.detect.grade;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import com.pengtu.entity.IdEntity;
import com.pengtu.utils.MathsUtils;

/**
 * @author Administrator
 * 
 */
@Entity
@Table(name="T_Q_GRADE_SUBENTRY")
public class Subentry extends IdEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String subentryName;
	private String subentryValue;
	private String subentryCode;
	private String remark;
	private Integer checkTotal;
	private Integer qualifiedTotal;
	private Branch branch;
	

	@Column(name="SUBENTRYNAME")
	public String getSubentryName() {
		return subentryName;
	}

	public void setSubentryName(String subentryName) {
		this.subentryName = subentryName;
	}

	@Column(name="SUBENTRYVALUE")
	public String getSubentryValue() {
		return subentryValue;
	}

	public void setSubentryValue(String subentryValue) {
		this.subentryValue = subentryValue;
	}

	@Column(name="SUBENTRYCODE")
	public String getSubentryCode() {
		return subentryCode;
	}

	public void setSubentryCode(String subentryCode) {
		this.subentryCode = subentryCode;
	}

	@Column(name="REMARK")	
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@Column(name="CHECKTOTAL")
	public Integer getCheckTotal() {
		return checkTotal;
	}

	public void setCheckTotal(Integer checkTotal) {
		this.checkTotal = checkTotal;
	}

	@Column(name="QUALIFIEDTOTAL")
	public Integer getQualifiedTotal() {
		return qualifiedTotal;
	}

	public void setQualifiedTotal(Integer qualifiedTotal) {
		this.qualifiedTotal = qualifiedTotal;
	}
	

	//合格率
	@Transient
	public  Double  getPercentPass() {
		return MathsUtils.formatDouble(MathsUtils.mul(MathsUtils.div(this.getQualifiedTotal(),this.getCheckTotal())), 2);
	}

	@Override
	@Transient
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((subentryCode == null) ? 0 : subentryCode.hashCode());
		return result;
	}

	@Override
	@Transient
	public boolean equals(Object obj) {
		if (this== obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Subentry other = (Subentry) obj;
		if (subentryCode == null) {
			if (other.subentryCode != null)
				return false;
		} else if (!subentryCode.equals(other.subentryCode))
			return false;
		return true;
	}

	//加权得分
	@Transient
	public Double getPoint(){
		return MathsUtils.mul(this.getPercentPass(),new Double(this.getSubentryValue()));
	}

	@ManyToOne(cascade=CascadeType.REMOVE)
	@JoinColumn(name="BRANCHID")
	@Fetch(FetchMode.JOIN)
	public Branch getBranch() {
		return branch;
	}

	public void setBranch(Branch branch) {
		this.branch = branch;
	}
	
	

}
